package com.emuporium.gymrat.server.exercise;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.emuporium.gymrat.server.data.ExerciseDB;
import com.emuporium.gymrat.server.data.User;
import com.emuporium.gymrat.server.data.UserDB;
import com.emuporium.gymrat.server.data.Variation;

@SuppressWarnings("serial")
public class ExerciseVariationListServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		User user = UserDB.selectUser(request.getRemoteUser());
		request.setAttribute("user", user);

		ArrayList<Variation> variations = ExerciseDB
				.selectAllVariations(user.getId());

		request.setAttribute("variations", variations);
		request.setAttribute("redir", request.getParameter("redir"));

		String url = "/exercise/variation/list.jsp";
		RequestDispatcher dispatcher = getServletContext()
				.getRequestDispatcher(url);
		dispatcher.forward(request, response);
	}

}
